package edu.gyc.lover.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FilenameFilter;

import java.util.Arrays;
import java.util.List;

@Slf4j
public class FileUtil {
    public static String getImgsPath() {
        //String filePath = request.getServletContext().getRealPath("imgs/");
        String projectPath = System.getProperty("user.dir");
        //根据自己系统的resource 目录所在位置进行自行配置
        String destDir = projectPath + File.separator+"src"+File.separator+"main"+ File.separator +
                "resources"+File.separator+"static"+File.separator+"imgs"  + File.separator;
        log.info("destDir:{}",destDir);
        return destDir;
    }

    public static List<String > getPicNames() {
        String path=getImgsPath();
        File file = new File(path);
        List<String> picnames = null;
            try {
          picnames = Arrays.asList(file.list(new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                    String[] kzms = {"jpg", "jpeg", "bmp","png"};
                    for (String kzm : kzms) {
                        if (name.endsWith(kzm)) {

                            return true;
                        }
                    }

                    return false;
                }
            }));


        } catch (Exception e) {
            e.printStackTrace();
        }
        return picnames;
    }
}
